home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 38 / Amiga Format CD38 (1999-03-15)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-04].iso / -seriously_amiga- / programming / other / wild / developer / examples / src / ppctimagemapping / startup.c < prev    next >
C/C++ Source or Header  |  1999-01-25  |  2KB  |  95 lines

  1. /*
  2. **    My Startup File...
  3. */
  4.  
  5. #include <exec/exec.h>
  6. #include <inline/exec.h>
  7. #include <intuition/intuition.h>
  8. #include <graphics/gfxbase.h>
  9. #include <dos/dosextens.h>
  10. #include <workbench/startup.h>
  11. #include <exec/libraries.h>
  12. #include <wild/wild.h>
  13.  
  14. #define SysBase *(struct ExecBase **)4l
  15. struct IntuitionBase *IntuitionBase;
  16. struct GraphicsBase *GraphicsBase;
  17. struct DOSBase *DOSBase;
  18. struct Library *IffParseBase;
  19. struct Process *ThisTask;
  20. struct WBStartup *WBMessage=NULL;
  21. struct WildBase *WildBase;
  22.  
  23. static void shutup(void);
  24. static void closelibs(void);
  25. static int openlibs(void);
  26. extern int main(char *commandline);
  27. extern void _exit(int err);
  28.  
  29. // This is just to call the program's main. Must do nothing.
  30. void starter(char *commandline)    
  31. {
  32.   exit(main(commandline));
  33. }
  34.  
  35. // This is to exit anytime from the program. Calls shutup and exits.
  36. // No stack problems, entry.o handles it.
  37. void exit(int err)            
  38. {
  39.   shutup(); 
  40.   _exit(err);
  41. }
  42.  
  43. // This is called by main() at start, is the startup init.Openlibs,WBMessage,...
  44. int __main(void)
  45. {
  46.   struct MsgPort *taskport;
  47.   if (!(openlibs()))
  48.    exit(-1);
  49.   ThisTask=(struct Process *)FindTask(NULL);
  50.   if (!ThisTask->pr_CLI)
  51.    {
  52.    taskport=&ThisTask->pr_MsgPort;
  53.    WaitPort(taskport);
  54.    WBMessage=(struct WBStartup *)GetMsg(taskport);   
  55.    } 
  56. }
  57.  
  58. // This frees, closes everything opened or allocated in __main.
  59. static void shutup(void)
  60. {
  61.   closelibs();
  62.   if (WBMessage)
  63.    ReplyMsg((struct Message *)WBMessage);
  64. }
  65.  
  66. #define OpenLib(base,name,ver) \
  67.  if (!(base=OpenLibrary(name,ver))) \
  68.   {return(FALSE);} 
  69.  
  70. static int openlibs(void)
  71. {
  72.   SysBase=*(struct ExecBase **)4l;
  73.   
  74.   OpenLib(IntuitionBase,"intuition.library",37);
  75.   OpenLib(GraphicsBase,"graphics.library",37);
  76.   OpenLib(IffParseBase,"iffparse.library",37);
  77.   OpenLib(DOSBase,"dos.library",37);
  78.   OpenLib(WildBase,"wild.library",1);
  79. }
  80.  
  81. #define CloseLib(base) \
  82.  if (base) \
  83.   {CloseLibrary(base); \
  84.    base=NULL;}
  85.    
  86. static void closelibs(void)
  87. {
  88.   CloseLib(IntuitionBase);
  89.   CloseLib(GraphicsBase);
  90.   CloseLib(IffParseBase);
  91.   CloseLib(DOSBase);
  92.   CloseLib(WildBase);
  93. }
  94.  
  95.